package com.jinsi.service.yrf.iml;
import com.jinsi.constant.YrfConstant;
import com.jinsi.mapper.yrf.AdministratorLoginLogMapper;
import com.jinsi.pojo.SyLoginLog;
import com.jinsi.pojo.SyUser;
import com.jinsi.service.yrf.AdministratorLoginLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.net.InetAddress;
import java.util.List;

@Service
@Transactional
public class AdministratorLoginLogServiceImpl implements AdministratorLoginLogService {
    @Autowired
    private AdministratorLoginLogMapper administratorLoginLogMapper;
    @Override
    public List<SyLoginLog> getAll(String logLoginAccount, String logLoginName) {
        return administratorLoginLogMapper.getAll(logLoginAccount,logLoginName, YrfConstant.LOG_JURISDICTION);
    }

    @Override
    public void administratorLoginLogdelete(int loginLogId) {
        administratorLoginLogMapper.administratorLoginLogdelete(loginLogId);
    }

    @Override
    public void insertadministratorLoginLog(SyUser syUser) throws Exception{

        SyLoginLog sylog = new SyLoginLog();
        sylog.setLogLoginAddress(YrfConstant.DI_ZHI);
        InetAddress addr = InetAddress.getLocalHost();
        String ip = addr.getHostAddress();
        sylog.setLogLoginIp(ip);
        sylog.setLogOrderSource(YrfConstant.LOGIN_STA);
        sylog.setLogLoginName(syUser.getUserName());
        sylog.setLogLoginAccount(syUser.getUserAccount());
        sylog.setLogJurisdiction(syUser.getDepartmentId());
        int num = administratorLoginLogMapper.insertadministratorLoginLog(sylog);
        if(num == 0){
            throw new Exception();
        }
    }

    @Override
    public List<SyLoginLog> usergetAll(String logLoginAccount, String logLoginName) {
        return administratorLoginLogMapper.usergetAll(logLoginAccount,logLoginName,YrfConstant.LOG_JURISDICTION);
    }


}
